﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Popup.Master" AutoEventWireup="true"
    CodeBehind="PropertySelectedList.aspx.cs" Inherits="PromotionEngine.PropertySelectedList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <style type="text/css">
        .highlighted-row
        {
            font-weight: bold;
        }
        #grid tbody tr:hover
        {
            cursor: pointer;
        }
    </style>
    <script type="text/javascript">
        var oCustomerPropertyLink = {};
        var oCustomer = {};
        var oCustomerPropertyDetail = {};
        var gird;
        var propertyForDetailID = 0;
        var customerID = 0;
        var referenceName;
        var propertyType = '1';
        var checkedIds = {};
        function onChange(arg) {
            var selectedRows = this.select();
            var selectedDataItems = [];
            for (var i = 0; i < selectedRows.length; i++) {
                var dataItem = this.dataItem(selectedRows[i]);
                selectedDataItems.push(dataItem);
            }
            if (selectedDataItems.length > 0) {
                parent.ChooseProperty(selectedDataItems[0].PropertyDetailID, selectedDataItems[0].PropertyDetailName);
            }
        }
        $(document).ready(function () {
            //Load Grid
            propertyType = $('#<%=hdnPropertyType.ClientID%>').val();
            grid = $("#grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "PropertySelectedList.aspx/GetPropertys",
                            data: '',
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "read") {
                                return { strPropertyType: kendo.stringify(propertyType) };
                            }
                        },
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: "d.Data",
                        total: "d.Count",
                        model: {
                            id: "PropertyID",
                            fields: {
                                PropertyID: { type: "string" },
                                PropertyCode: { type: "string" },
                                PropertyName: { type: "string" }
                            }
                        }
                    }
                },
                sortable: true,
                resizable: true,
                height: 520,
                batch: true,
                detailTemplate: kendo.template($("#template").html()),
                detailInit: detailInit,
                dataBound: function () {
                    var grid = $("#grid").data("kendoGrid");
                    var gridData = grid.dataSource.view();
                    for (var i = 0; i < gridData.length; i++) {
                        grid.table.find("tr[data-uid='" + gridData[i].uid + "']").addClass("highlighted-row");
                    }
                    //this.expandRow(this.tbody.find("tr.k-master-row").first());
                    //this.expandRow(this.tbody.find("tr.k-master-row"));
                },
               
                columns: [{ field: "PropertyID", title: "Property ID", width: 100, hidden: true },
                            { field: "PropertyCode", title: "Property Code", width: 200 },
                            { field: "PropertyName", title: "Property Name", width: 320}]
            }).data("kendoGrid");
            $("#grid tr").css("background-color", "red");
        });
        function detailInit(e) {
            var detailRow = e.detailRow;
            //Detail
            detailRow.find(".gridPropertyDetail").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "PropertySelectedList.aspx/GetPropertyDetail",
                            data: '',
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "read") {
                                return { propertyID: e.data.PropertyID, strPropertyType: kendo.stringify(propertyType) };
                            }
                        },
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true,
                        pageSize: 7,
                        filter: { field: "PropertyID", operator: "eq", value: e.data.PropertyID }
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: "d.Data",
                        total: "d.Count",
                        model: {
                            id: "PropertyID",
                            fields: {
                                PropertyID: { type: "string" },
                                PropertyCode: { type: "string" },
                                PropertyName: { type: "string" }
                            }
                        }
                    }
                },
                change: onChange,
                selectable: "row",
                sortable: true,
                resizable: true,
                batch: true,
                columns: [{ field: "PropertyDetailID", title: "Property Detail ID", width: 100, hidden: true },
                            { field: "PropertyDetailCode", title: "Property Detail Code", width: 200 },
                            { field: "PropertyDetailName", title: "Property Detail Name", width: 270 }
                            ]
            }).data("kendoGrid");
        }
      
    </script>
        <asp:HiddenField ID="hdnPropertyType" runat="server"></asp:HiddenField>
    <script type="text/x-kendo-template" id="template">
                    <div>
                        <div class="gridPropertyDetail"></div>
                    </div>
    </script>
    <table style="width: 100%;">
        <tr>
            <td>
                <div id="grid">
                </div>
            </td>
        </tr>
    </table>
</asp:Content>
